﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using HIWSystem.Models;
using HIWSystem.Common;

namespace HIWSystem.ViewModel
{
    public class MenuLevelDescViewModel : ViewModelBase
    {
        #region 命令
        private RelayCommand loadPageCmd;

        public RelayCommand LoadPageCmd
        {
            get 
            {
                if (loadPageCmd==null)
                {
                    loadPageCmd = new RelayCommand(LoadPage);
                }
                return loadPageCmd;
            }
            set { loadPageCmd = value; }
        }


        #endregion
        #region 属性
        private ObservableCollection<MenuLevelEntity> menuLevelResource;
        /// <summary>
        /// 菜单权限资源
        /// </summary>
        public ObservableCollection<MenuLevelEntity> MenuLevelResource
        {
            get { return menuLevelResource; }
            set { menuLevelResource = value; this.RaisePropertyChanged(() => MenuLevelResource); }
        }
        #endregion
        #region 方法
        /// <summary>
        /// 页面加载事件
        /// </summary>
        private void LoadPage()
        {
            DataTable dt = new DataTable();
            MenuLevelResource = new ObservableCollection<MenuLevelEntity>();
            dt = BusinessProcess.GetMenuLevelInfo();
            if (dt.Rows.Count>0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    MenuLevelResource.Add(
                        new MenuLevelEntity
                        {
                            MenuCn = dt.Rows[i]["MenuCn"].ToString(),
                            MenuEn = dt.Rows[i]["MenuEn"].ToString(),
                            Level = dt.Rows[i]["ActorLevel"].ToString()
                        });
                }
            }
        }
        #endregion
    }
}
